package com.mq.config3_direct;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectModelConfig {
    /**
     * 1. 创建一个交换机: direct.exchange
     * 2. 创建两个队列: direct.queue1、direct.queue2
     * 3. 将队列绑定到交换机
     *      direct.queue1  direct.exchange  gz
     *      direct.queue2  direct.exchange  sz
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct.exchange");
    }
    @Bean
    public Queue directQueue1() {
        return new Queue("direct.queue1");
    }
    @Bean
    public Queue directQueue2() {
        return new Queue("direct.queue2");
    }

    // direct.queue1 队列绑定到交换机
    @Bean
    public Binding directBinding1(@Qualifier("directQueue1") Queue directQueue1, @Qualifier("directExchange") DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("gz");
    }

    // direct.queue2 队列绑定到交换机
    @Bean
    public Binding directBinding2(@Qualifier("directQueue2") Queue directQueue2, @Qualifier("directExchange") DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue2).to(directExchange).with("sz");
    }
}
